package com.ruoyi.web.controller.applet;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysDictData;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.applet.domain.MiniProductModel;
import com.ruoyi.applet.service.IMiniProductModelService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品型号Controller
 *
 * @author liucan
 * @date 2024-03-25
 */
@RestController
@RequestMapping("/applet/model")
public class MiniProductModelController extends BaseController {
    @Resource
    private IMiniProductModelService miniProductModelService;

    @Resource
    private MiniLeagueController miniLeagueController;


    /**
     * 查询产品型号列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MiniProductModel miniProductModel, HttpServletRequest request) {
        startPage();
        miniProductModel.setToApplet(miniLeagueController.toApplet(request));
        List<MiniProductModel> list = miniProductModelService.selectMiniProductModelList(miniProductModel);
        return getDataTable(list,null);
    }

    /**
     * 新增产品型号
     */
    @Log(title = "产品型号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MiniProductModel miniProductModel, HttpServletRequest request) {
        miniProductModel.setToApplet(miniLeagueController.toApplet(request));
        return toAjax(miniProductModelService.insertMiniProductModel(miniProductModel));
    }

    /**
     * 修改产品型号
     */
    @Log(title = "产品型号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MiniProductModel miniProductModel, HttpServletRequest request) {
        miniProductModel.setToApplet(miniLeagueController.toApplet(request));
        return toAjax(miniProductModelService.updateMiniProductModel(miniProductModel));
    }

    /**
     * 删除产品型号
     */
    @Log(title = "产品型号", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(miniProductModelService.deleteMiniProductModelByIds(ids));
    }

    /**
     * 查询字典数据
     */
    @GetMapping("/dict")
    public AjaxResult dict(SysDictData dictData) {
        List<MiniProductModel> list = miniProductModelService.selectDictDataList1(dictData);
        return AjaxResult.success(list);
    }

    /**
     * 查询字典数据---膜类型
     */
    @GetMapping("/dictType")
    public AjaxResult dictType(SysDictData dictData) {
        List<SysDictData> list = miniProductModelService.selectDictType(dictData);
        return AjaxResult.success(list);
    }

    /**
     * 导出产品型号列表
     */
    @Log(title = "产品型号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MiniProductModel miniProductModel) {
        List<MiniProductModel> list = miniProductModelService.selectMiniProductModelList(miniProductModel);
        ExcelUtil<MiniProductModel> util = new ExcelUtil<MiniProductModel>(MiniProductModel.class);
        util.exportExcel(response, list, "产品型号数据");
    }

    /**
     * 获取产品型号详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(miniProductModelService.selectMiniProductModelById(id));
    }
/**
 *未分页的产品型号获取
 */

@GetMapping("/listNoPageModel")
public TableDataInfo listNoPage(MiniProductModel miniProductModel, HttpServletRequest request) {
//    startPage();
    miniProductModel.setToApplet(miniLeagueController.toApplet(request));
    List<MiniProductModel> list = miniProductModelService.selectMiniProductModelList(miniProductModel);
    return getDataTable(list,null);
}

    @GetMapping("/newlist")
    public TableDataInfo newlist(MiniProductModel miniProductModel, HttpServletRequest request) {
//    startPage();
        miniProductModel.setToApplet(miniLeagueController.toApplet(request));
        List<MiniProductModel> list = miniProductModelService.selectMiniProductModelList(miniProductModel);
        return getDataTable(list,null);
    }






}
